package com.test.demo.springbootdemo.service;

import com.test.demo.springbootdemo.entity.User;
import com.test.demo.springbootdemo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceOther {
    @Autowired
    UserMapper userMapper;

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
    public void updateById2(Long id, Integer age) throws Exception {
        User user = userMapper.selectById(2);
        user.setAge(age+1000);
        userMapper.updateById(user);
        //手动回滚
        //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
    }
}
